﻿using System;
using System.Collections.Generic;

namespace dk.Helper.Base.Core
{
    public class Attacks : List<IAttack>, IAttacks
    {
        #region IAttacks Members

        /// <summary>
        /// Adds the specified attack.
        /// </summary>
        /// <param name="attack">The attack.</param>
        public new void Add(IAttack attack)
        {
            if (!Contains(attack))
            {
                base.Add(attack);
                OnChanged(new EventArgs());
            }
        }

        /// <summary>
        /// Removes the specified attack.
        /// </summary>
        /// <param name="attack">The attack.</param>
        public new void Remove(IAttack attack)
        {
            if (Contains(attack))
            {
                base.Remove(attack);
                OnChanged(new EventArgs());
            }
        }

        /// <summary>
        /// Occurs when this instance is changed.
        /// </summary>
        public event EventHandler Changed;

        #endregion

        /// <summary>
        /// Raises the <see cref="Changed"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnChanged(EventArgs e)
        {
            if (Changed != null) Changed(this, e);
        }
    }
}